package com.weixin.common.core.doman;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 数据返回对象
 *
 * @author wangchunhui
 * @date 2022/2/15 10:49
 */
@Data
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Result {

    private boolean success;
    private String code;
    private String message;
    private Object data;
    private Long total;

    public Result(ResultCode code) {
        this.success = code.success;
        this.code = code.code;
        this.message = code.message;
    }

    public Result(ResultCode code, Object data) {
        this.success = code.success;
        this.code = code.code;
        this.message = code.message;
        this.data = data;
    }

    public Result(ResultCode code, long total, Object data) {
        this.success = code.success;
        this.code = code.code;
        this.message = code.message;
        this.data = data;
        this.total = total;
    }

    public static Result SUCCESS(Object result) {
        return new Result(ResultCode.SUCCESS, result);
    }

    public static Result SUCCESS(Long total, Object result) {
        return new Result(ResultCode.SUCCESS, total, result);
    }

    public static Result SUCCESS() {
        return new Result(ResultCode.SUCCESS);
    }

    public static Result FAIL() {
        return new Result(ResultCode.FAIL);
    }

    public static Result FAIL(String message) {
        return new Result(ResultCode.FAIL, message);
    }
}
